﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace AutoServey
{
    class XmlInput
    {
        public double getDirection(string direction)
        {
            switch (direction)
            {
                case "North":
                    return 0;
                case "NorthEast":
                    return 45;
                case "East":
                    return 90;
                case "SouthEast":
                    return 135;
                case "South":
                    return 180;
                case "SouthWest":
                    return 225;
                case "West":
                    return 270;
                case "NorthWest":
                    return 315;
            }
            return -1;
        }
        public void readXml(string path)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlElement rootElement = doc.DocumentElement;
            string parkGeometry = rootElement.GetElementsByTagName("Geometry")[0].InnerText;
            string panoLocation = rootElement.GetElementsByTagName("PanoLocation")[0].InnerText;
            frmMainMethods fmMethods = new frmMainMethods();
             double orientation=-1;
            try
            {
                string direction = rootElement.GetElementsByTagName("Direction")[0].InnerText;
                orientation = getDirection(direction);
            }
            catch
            {
                orientation = fmMethods.getOritation(parkGeometry, panoLocation);
            }
            GetPanoImg getPanoImg = new GetPanoImg();
            getPanoImg.searchPano(panoLocation, orientation, path);
        }

        public bool hasPanoLocation(string xmlPath)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlElement rootElement = xmlDoc.DocumentElement;
            if (rootElement.GetElementsByTagName("PanoLocation").Count > 0)
            {
                if (rootElement.GetElementsByTagName("PanoLocation")[0].InnerText != "")
                {
                    return true;
                }
            }
            return false;
        }

        public string getTaskType(string xmlPath)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlElement rootElement = xmlDoc.DocumentElement;
            string DocumentType = rootElement.GetElementsByTagName("TaskType")[0].InnerText;
            return DocumentType;
        }

        public string getGeometry(string xmlPath)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlElement rootElement = xmlDoc.DocumentElement;
            string geometry = rootElement.GetElementsByTagName("Geometry")[0].InnerText;
            return geometry;
        }
    }
}
